﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Meditime.Domain
{
    public partial class ShiftRecording
    {

        partial void ValidateMarkAsOffDuty(Guid id, DateTime shiftStart, Guid staffMemberId)
        {
            CheckShiftStartTime(shiftStart);
        }

        partial void ValidateGoOnHoliday(Guid id, DateTime shiftStart, Guid staffMemberId)
        {
            CheckShiftStartTime(shiftStart);
        }

        partial void ValidateRemoveFromRoster(Guid id, DateTime shiftStart, Guid staffMemberId)
        {
            CheckShiftStartTime(shiftStart);
        }

        partial void ValidateStartOnCall(Guid id, DateTime shiftStart, Guid staffMemberId)
        {
            CheckShiftStartTime(shiftStart);
        }

        partial void ValidateStartWorking(Guid id, DateTime shiftStart, Guid staffMemberId)
        {
            CheckShiftStartTime(shiftStart);

            
            if (this.CurrentState.Name == States.OffDuty && this.ShiftStart.AddHours(8) > shiftStart)
                throw new ApplicationException("Off-Duty Shifts must be at least 8 hours in length.");
        }

        private void CheckShiftStartTime(DateTime shiftStart)
        {
            if (shiftStart.CompareTo(this.ShiftStart) == -1)
                throw new ApplicationException("A new shift cannot be added that is earlier that the Current Shift start time.");
        }


    }
}
